#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\res\earth.ico
#AutoIt3Wrapper_Outfile=out\config-network.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.16.1
 Author:         myName

 Script Function:
	Template AutoIt script.

#ce ----------------------------------------------------------------------------
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiComboBox.au3>
; Script Start - Add your code below here
;Run (@SystemDir&"\control.exe netconnections");打开网络连接
;WinWaitActive("网络连接")



; 打开网络连接窗口
Run("control.exe ncpa.cpl")
Local $aControl = WinWaitActive("网络连接", "网络连接", 3)

Local $aPos = WinGetPos($aControl)
Local $eX,$eY
;---------------------------------
;列表宽带步长250 高60
For $i = 1 To 5 Step +1
	WinWaitActive("网络连接", "网络连接", 1)
	$line = Int($aPos[2] / 250)
	$x = Mod($i , $line) =  0 ? $line * 250 -50 : Mod($i , $line) * 250 - 50;
	$y = $i <= $line          ? 40 : ( Mod($i , $line) =  0 ? (Int($i / $line) -1) * 50 + 40 : Int($i / $line) * 50 + 40);

	ControlClick("网络连接", "", "", "right", 1, $x , $y)
	;Sleep(500)
	;ControlSend($aControl,"","", "r")
	Send("r")
	;Sleep(500)
	;WinClose("[active]")

	Local $aEthernet = WinWaitActive("Ethernet0 属性", "连接时使用:", 1)
	WinClose("[active;REGEXPTITLE:^.*属性.*$]")
	If $aEthernet = 0 Then ;0 没找到 关闭窗口
		;没找到
	Else
		;MsgBox($MB_SYSTEMMODAL, "", "The value of $i is: " & $i)
		$eX = $x
		$eY = $y
		ExitLoop
	EndIf
Next
;--------------------------------------------------
;MsgBox($MB_SYSTEMMODAL, "", "设置共享" )
ControlClick("网络连接", "", "", "right", 1, $eX,$eY)
;Sleep(100)
;ControlSend($aControl,"","", "r")
Send("r")
;Exit
Local $aEthernet = WinWaitActive("Ethernet0 属性", "连接时使用:", 3)
ConsoleWrite($aEthernet& "---Ethernet0 ------>"& @CRLF)
Send("^+{TAB}")
;Sleep(100)
ControlFocus   ($aEthernet, "Internet 连接共享:", "[ID:105]" )
Send("{+}"); 选中
;_GUICtrlComboBox_SetCurSel("[CLASS:ComboBox; INSTANCE:1]", 3)
;$occurrence = ControlCommand ($aEthernet, "", "[CLASS:ComboBox; INSTANCE:1]", "FindString", 'Ethernet1')
WinActivate($aEthernet)
;ControlCommand ($aEthernet, "", "[CLASS:ComboBox; INSTANCE:1]", "ShowDropDown", "")
ControlCommand ($aEthernet, "", "[CLASS:ComboBox; INSTANCE:1,ID:107]", "SelectString", 'Ethernet1')
;MsgBox($MB_SYSTEMMODAL, "", "请确认" )
;Sleep(1000)
Send("{ENTER}")
Example()
Send("!y")
;Sleep(3000)
WinWaitClose ( $aEthernet)
;----------------------------------------------------
;MsgBox($MB_SYSTEMMODAL, "", "取消共享" )
ControlClick("网络连接", "", "", "right", 1, $eX,$eY)

Send("r")
Local $aEthernet = WinWaitActive("Ethernet0 属性", "连接时使用:", 3)
ConsoleWrite($aEthernet& "---Ethernet0 ------>"& @CRLF)
Send("^+{TAB}")

ControlFocus ( $aEthernet, "Internet 连接共享:", "[ID:105]" )
Send("{-}"); 选中

Send("{ENTER}")
;
WinWaitClose ( $aEthernet)
Sleep(1000)
;----------------------------------------------------
;MsgBox($MB_SYSTEMMODAL, "", "设置共享" )
ControlClick("网络连接", "", "", "right", 1,  $eX,$eY)

Send("r")
Local $aEthernet = WinWaitActive("Ethernet0 属性", "连接时使用:", 3)
ConsoleWrite($aEthernet& "---Ethernet0 ------>"& @CRLF)
Send("^+{TAB}")

ControlFocus ( $aEthernet, "Internet 连接共享:", "[ID:105]" )
Send("{+}"); 选中

WinActivate($aEthernet)
ControlCommand ($aEthernet, "", "[CLASS:ComboBox; INSTANCE:1,ID:107]", "SelectString", 'Ethernet1')
Send("{ENTER}"); 确定
Send("!y")

;--------------------------------------------------

WinClose($aControl)

;Send("{ENTER}")
;Send("!c")
; 打开选中网卡的属性面板
;ControlClick($aControls, "", "Ethernet0", "right", 1, 1)
;Send("p")




Func Example()
	; Sample script with two user-defined functions.
	; Notice the use of variables, ByRef and Return.
	Local $aErr = WinWaitActive("本地网络", "必须选择一个连接为专用网络", 3)
	If $aErr = 0 Then
		;Failure: 0 if timeout occurred.
	Else
		Send("{ESC}")
		MsgBox($MB_SYSTEMMODAL, "Error", "必须选择一个连接为专用网络." & @CRLF , 3)
		;Exit
	EndIf
EndFunc



Local $aVar[3]